//
//  OrderUUIDConverter.swift
//  Distance
//
//  Created by changhe on 2025/4/24.
//

/// 订单ID转换协议
///
/// 此协议定义了订单ID和UUID之间的相互转换方法
/// 实现此协议可以自定义订单ID的格式和转换规则
public protocol YLOrderIDConverter {
	/// 将订单ID转换为UUID格式
	/// - Parameter orderId: 原始订单ID
	/// - Returns: 转换后的UUID格式字符串
	func toUUID(_ orderId: String) -> String
	
	/// 将UUID格式转换回原始订单ID
	/// - Parameter uuid: UUID格式字符串
	/// - Returns: 原始订单ID
	func fromUUID(_ uuid: String) -> String
}


internal class YLOrderUUIDTransformer {
		
	private static var converter: YLOrderIDConverter = DefaultConverter()
	
	private class DefaultConverter: YLOrderIDConverter {
		func toUUID(_ orderId: String) -> String {
			return orderId
		}
		
		func fromUUID(_ uuid: String) -> String {
			return uuid
		}
	}
	
	public class func configure(with converter: YLOrderIDConverter?) {
		guard let converter else { return }
		Self.converter = converter
	}
	
	class func toUUID(_ orderId: String) -> String {
		return converter.toUUID(orderId)
	}
	
	class func fromUUID(_ uuid: String) -> String {
		return converter.fromUUID(uuid)
	}
}
